package com.company.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Date;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/12/30 20:59
 */
public class TimeClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf msg1 = (ByteBuf) msg;
        try {
            long l = (msg1.readUnsignedInt() - 2208988800L) * 1000L;
            System.out.println(new Date(l));
            ctx.close();
        } finally {
            msg1.release(); // 释放msg1 引用变量
        }

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
